#!/usr/bin/python

# **************************************************
# Author        : Lee, Gwanghee
# Datetime      : 2011, 02, 07
# **************************************************

__author__ = 'ilous12@gmail.com (Lee, Gwanghee)'

import _base # for hangul
from google.appengine.ext import db
from geo.geomodel import GeoModel

# A Model for a Push (C2DM, APNS)
class PushConfigDB(db.Model):
    name = db.StringProperty()
    pushType = db.StringProperty()
    authToken = db.StringProperty()
    modified = db.DateTimeProperty(auto_now=True)
  
# A Model for a ChatMessage
class ChatMessage(db.Model):
    user = db.ReferenceProperty()
    text = db.StringProperty()
    modified = db.DateTimeProperty(auto_now=True)
    
# A Model for a Push Users
class DeviceRegistrationDB(GeoModel):
    name = db.StringProperty()
    status = db.StringProperty()
    deviceId = db.StringProperty()
    deviceType = db.StringProperty()
    registrationToken = db.StringProperty()
    modified = db.DateTimeProperty(auto_now=True)
    data = db.BlobProperty()
    thumbnail_data = db.BlobProperty()
    
    @staticmethod
    def public_attributes():
        return ['title', 'content', ]

    def _get_latitude(self):
        return self.location.lat if self.location else None

    def _set_latitude(self, lat):
        if not self.location:
            self.location = db.GeoPt()
        self.location.lat = lat
        latitude = property(_get_latitude, _set_latitude)

    def _get_longitude(self):
        return self.location.lon if self.location else None

    def _set_longitude(self, lon):
        if not self.location:
            self.location = db.GeoPt()
        self.location.lon = lon

        longitude = property(_get_longitude, _set_longitude)
